var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');
const pay = require('../../../services/pay.js');
Page({
    data: {
        orderList: [],
        dd: '',
        hidden: false,
        page: 1,
        size: 10,
        hasMore: true,
        hasRefesh: false,
        status:1,
    },
    onLoad: function(options) {
        // 页面初始化 options为页面跳转所带来的参数
        this.getOrderList();
    },
    onPullDownRefresh: function () {
        this.getOrderList();
    },
    changeStatus:function(e){
        this.setData({
            status:e.currentTarget.dataset.status
        })
        this.getOrderList();

    },
    getOrderList: function() {
        let that = this;
        wx.showLoading({
            title: '加载中...',
        })
        that.setData({
            page: 1,
            hasMore:true
        });
        let pram={
            current:that.data.page,
            size:that.data.size
        }
        util.request(api.wholesaler.wholesalerOrderList+'/'+that.data.status,pram,'post').then(function(res) {
            if (res.code == 200) {
                wx.hideLoading()
                wx.stopPullDownRefresh();
                that.setData({
                    orderList: res.result
                });
                if (res.result.length < that.data.size) {
                    that.setData({
                        hasMore: false,
                    })
                }

            }
        });
    },
    onReady: function() {
        // 页面渲染完成
    },
    onShow: function() {
        // 页面显示
    },
    onHide: function() {
        // 页面隐藏
    },
    onUnload: function() {
        // 页面关闭
    },
    onReachBottom(){
        this.loadMore()
    },
    loadMore: function() {
        var that = this;
        if (!this.data.hasMore) return
        wx.showLoading({
            title: '加载中...',
        })
        let pram={
            current:++that.data.page,
            size:that.data.size
        }
        util.request(api.wholesaler.wholesalerOrderList+'/'+that.data.status,pram,'post').then(function(res) {
            if (res.code == 200) {
                that.setData({
                    orderList: that.data.orderList.concat(res.result)
                });
                if (res.result.length < that.data.size) {
                    that.setData({
                        hasMore: false,
                    })
                }
                wx.hideLoading()
            }
        });
    }
})